<!DOCTYPE html>
<head>
	<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
	<title>{$title} - {$settings.site.sitename}</title>
	{include file="public/css"}
  {include file="public/js"}
<style>
.banner-title{font-size:38px;line-height:150px;text-align:center;}
</style>

</head>
<body class="layui-bg-gray">
{include file="public/header"}
<div class="layui-container">
<div class="layui-main trade-add">
<div class="layui-row layui-col-space10">

   <!-- 项目进度条 -->
   {include file="trade/order_step"}


<div class="layui-main">


  <!-- 交易信息 -->
  {if  $Think.session.uid == $guaranteeData.buyer_uid}
  <!-- 显示卖家信息 -->
  <blockquote class="layui-elem-quote layui-card">卖家信息</blockquote>
    <div class="layui-card-body layui-card ">
      <div class="layui-inline" style="width:15%;text-align:center">
        <p >
        <a href="/u/{$guaranteeData.seller_info.uid}"  >{:avatar($guaranteeData.seller_info.uid,128)}</a>
        </p>
        <p style="text-align:center;padding:10px"> <a href="">{$guaranteeData.seller_info.username}</a></p>
      </div>
      <div class="layui-inline" style="width:70%;">

           <p>联系电话：{if $guaranteeData.seller_info.mobile}{$guaranteeData.seller_info.mobile}{else} -- {/if}  QQ:{if $guaranteeData.seller_info.qq}{$guaranteeData.seller_info.qq}{else} -- {/if}  所在地：{:show_area($guaranteeData.seller_info.provid,$guaranteeData.seller_info.cityid,$guaranteeData.seller_info.distid)}</p>
           <p>最近成交：买 {$guaranteeData.seller_info.buy_num} 单，卖 {$guaranteeData.seller_info.sell_num} 单</p>
           <p>他的收入：{$seller_income}元</p>
          <p>工作速度：{:stars('speed',$guaranteeData.seller_info.buyer_works_peed)} 工作质量:{:stars('quality',$guaranteeData.seller_info.buyer_works_quality)} 工作态度： {:stars('attitude',$guaranteeData.seller_info.buyer_works_attitude)}
           </p> 
          
      </div>
{elseif $Think.session.uid == $guaranteeData.seller_uid}
<!-- 显示买家信息 -->
<blockquote class="layui-elem-quote layui-card">买家信息</blockquote>
  <div class="layui-card-body layui-card ">
      <div class="layui-inline" style="width:15%;text-align:center">
        <p><a href="/u/{$guaranteeData.buyer_uid}">
         {:avatar($guaranteeData.buyer_info.uid,128)}
       </a>
        </p>
        <p style="text-align:center;padding:10px"> <a href="">{$guaranteeData.buyer_info.username}</a></p>
      </div>
      <div class="layui-inline" style="width:70%;">

           <p>联系电话：{if $guaranteeData.buyer_info.mobile}{$guaranteeData.buyer_info.mobile}{else} -- {/if}  QQ:{if $guaranteeData.buyer_info.qq}{$guaranteeData.buyer_info.qq}{else} -- {/if}  所在地：{:show_area($guaranteeData.buyer_info.provid,$guaranteeData.buyer_info.cityid,$guaranteeData.buyer_info.distid)}</p>
           <p>最近成交: 买 {$guaranteeData.buyer_info.buy_num} 单，卖 {$guaranteeData.buyer_info.sell_num} 单 </p>
            <p>他的收入：{$buyer_income}元</p>
           <p>付款速度：{:stars('speed',$guaranteeData.buyer_info.seller_pay)} 工作态度:{:stars('attitude',$guaranteeData.buyer_info.seller_attitude)} 验收及时性： {:stars('check',$guaranteeData.buyer_info.seller_check)}
           </p> 
      </div>
{/if}

  </div>
</div>
<div class="layui-card">
  <div class="layui-card-body">
  <table class="layui-table" lay-even lay-skin="nob">
   <colgroup>
    <col width="800">
    <col width="200">
    <col width="200">
    <col width="200">
    <col width="200">
  </colgroup>
  <thead>
    <tr>
      <th>交易标题</th>
      <th>交易价格</th>
      <th>手续费支付方式</th>
      {if $Think.session.uid == $guaranteeData.buyer_uid}
      <th>我的支付</th>
      <th>卖家收入</th>
       {elseif $Think.session.uid == $guaranteeData.seller_uid}
       <th>我的收入</th>
       <th>买家支付</th>    
        {/if}

    </tr> 
  </thead>
  <tbody>
    <tr>
      <td>{$guaranteeData.title}</td> 
      <td class="orange">¥{$guaranteeData.price}</td>
      <td>{if $guaranteeData.fee_type ==1}买家全付{elseif guaranteeData.fee_type ==2}卖家全付{elseif guaranteeData.fee_type ==3}双方各付一半{/if}</td>
      {if $Think.session.uid == $guaranteeData.buyer_uid}
      <td class="orange">¥{$guaranteeData.buyer_pay}</td>
      <td class="orange">¥{$guaranteeData.seller_get}</td>
       {elseif $Think.session.uid == $guaranteeData.seller_uid}
       <td class="orange">¥{$guaranteeData.seller_get}</td> 
       <td class="orange">¥{$guaranteeData.buyer_pay}</td>

        {/if}


      
    </tr>
  </tbody>
</table>

<h2 style="margin-top:40px">交易详情</h2>
<hr>
<p>
{:htmlspecialchars_decode($guaranteeData.content)}
</p>


<div class="steps-pay" style="">

{if $Think.session.username == $guaranteeData.buyer}
<!-- 买家  六步骤-->
   {if $Request.param.step ==1}
     <!-- 创建订单 -->
   {elseif $Request.param.step ==2}
     <!-- 等待卖家确认 -->
     
     <h2 style="text-align:center;padding:40px;">您的中介请求已经发送成功，对方接受后将会通知您，请耐心等待。</h2>
   {elseif $Request.param.step ==3}
     <!-- 买家付款 -->
     <p style="text-align:right;font-size:20px;">需要支付：<span class="orange"> ¥{$guaranteeData.buyer_pay}</span></p>
     <p style="text-align:right;margin-top:10px">当前余额：<span > ¥{$user.money}</span></p>
      <h2 style="text-align:center;padding:40px;">对方已经接受您的中介请求，请尽快支付！</h2>
         {if $user.money < $guaranteeData.price}
              <p style="text-align:center"> 余额不足，请 <a href="{:url('@user/finance/recharge')}"  class="layui-btn layui-btn-primary">充值</a>
              </p>
        {else }
             <p style="text-align:center"><a href="javascript:;" class="layui-btn layui-btn-normal pay" data-url="{:url('@user/guarantee/updateOrderStatus',['id'=>$guaranteeData.id,'status'=>2])}">立即支付</a> <a href="" class="layui-btn layui-btn-primary refuse" data-url="{:url('@user/guarantee/updateOrderStatus',['id'=>$guaranteeData.id,'status'=>-1])}">取消订单</a>
             </p>
        {/if}
   {elseif $Request.param.step ==4}
     <!-- 等待卖家发货 -->
      <h2 style="text-align:center;padding:40px;">您已付款成功，等待对方发货！</h2>
      <p style="text-align:center">
        {if empty($guaranteeData['rights'])}
        <a href="javascript:;" class="layui-btn layui-btn-primary arbitration"  data-url="{:url('@user/rights/index',['id'=>$Request.param.id,'from'=>$user.uid,'to'=>$guaranteeData.seller_info.uid])}">申请仲裁</a>
        {else}
        等待仲裁处理！
        {/if}</p>

   {elseif $Request.param.step ==5}
     <!-- 买家确认 -->
    {if $guaranteeData.file}
    <div style="text-align:center;;"><a href="{$guaranteeData.file}" download="{$guaranteeData.file}" class="layui-icon layui-icon-download-circle" style="font-size:35px;margin:0 auto">源文件下载</a></div>
    {/if}
    <h2 style="text-align:center;padding:40px;">卖家已发货，请您确认验收！</h2>
    <p style="text-align:center;margin-bottom:10px;color:red">订单自动确认时间：  <span id="auto_time"></span>
    </p>

    <p style="text-align:center">
    <a href="javascript:;" class="layui-btn layui-btn-normal buyerConfirm" data-id="{$guaranteeData.id}">确认验收</a>
      {if empty($guaranteeData['rights'])}
    <a href="javascript:;" class="layui-btn layui-btn-primary arbitration"  
     data-url="{:url('@user/rights/index',['id'=>$Request.param.id,'from'=>$user.uid,'to'=>$guaranteeData.buyer_info.uid])}" >申请仲裁</a>
     {else}
等待仲裁处理！
     {/if}</p>

   {elseif $Request.param.step ==6}
    <!-- 买家评价 -->

     {if $guaranteeData.buyer_evaluate > 0 }
       {if $guaranteeData.seller_evaluate >0}
       <h2 style="text-align:center;padding:40px;">双方已评价！</h2>
       {else}
       <h2 style="text-align:center;padding:40px;">我已经评价！</h2>
       {/if}
     {else}
           <h2 style="text-align:center;padding:40px;">给卖家评价</h2>
             <form class="layui-form" action="">
                <div class="layui-form-item">
                  <label class="layui-form-label" style="width:120px">给对方的评价</label>
                  <div class="layui-input-inline" style="width:320px">
                     <input type="radio" name="buyer_evaluate" value="1" title="好评" checked>
                     <input type="radio" name="buyer_evaluate" value="2" title="中评" >
                     <input type="radio" name="buyer_evaluate" value="3" title="差评" >
                  </div>
                </div>
                  <div class="layui-form-item layui-form-text">
                    <label class="layui-form-label" style="width:120px">评价内容</label>
                    <div class="layui-input-inline" style="width:420px">
                      <textarea name="buyer_evaluate_content" placeholder="请输入评价内容" class="layui-textarea"></textarea>
                    </div>
                  </div>
                    <div class="layui-form-item">
            <label class="layui-form-label" style="width:120px">评价质量</label>
            <div class="layui-input-inline" style="width:620px">
    
                 <div class="layui-form-item">
                  <label class="layui-form-label">工作速度</label>
                    {:choose_stars('buyer_works_peed')}
               
                </div>
                   <div class="layui-form-item">
                  <label class="layui-form-label">完成质量</label>
                   {:choose_stars('buyer_works_attitude')}
           
                </div>
                   <div class="layui-form-item">
                  <label class="layui-form-label">工作态度</label>
                     {:choose_stars('buyer_works_quality')}
       
                </div>
          
            </div>
          </div>
                <div class="layui-form-item">
                <div class="layui-input-block">
                  <button class="layui-btn layui-btn-normal" lay-submit lay-filter="buyerEvaluate">提交</button>
                  
                </div>
             </div>
          </form>


     {/if}
 
   {/if}
  
  {elseif $Request.param.step ==7}  
     <h2 style="text-align:center;padding:40px;">订单已关闭！</h2>
{elseif $Think.session.username == $guaranteeData.seller}
<!-- 卖家 五步骤-->

   {if $Request.param.step ==2}
  <!-- 卖家确认订单 -->
     <h2 style="text-align:center;padding:40px;">等待您的确认！</h2>
     <div class="" style="text-align:center;padding:40px;"><a href="javascript:;" class="layui-btn layui-btn-normal accept" data-url="{:url('@user/guarantee/updateOrderStatus',['id'=>$guaranteeData.id,'status'=>1])}">接受交易请求</a><a href="javascript:;" class="layui-btn layui-btn-primary refuse" data-url=" {:url('@user/guarantee/updateOrderStatus',['id'=>$guaranteeData.id,'status'=>-1])}">拒绝</a></div>
   {elseif $Request.param.step ==3}
  <!-- 买家付款 -->
     <h2 style="text-align:center;padding:40px;">您已成功接受客户中介请求，请耐心等待买家付款。</h2>

   {elseif $Request.param.step ==4}
   <!-- 卖家发货 -->
   <h2 style="text-align:center;padding:40px;">买家已经支付成功，等待您的发货</h2>
   <form class="layui-form" action="" >
   <input name="id"  id="id" type="hidden" value="{$Request.param.id}">
   <input name="status"  id="status" type="hidden" value="3">
   <p >
        <div class="layui-form-item" style="width:600px;margin:0 auto;padding:30px">
        <label class="layui-form-label">上传源文件</label>
        <div class="layui-input-inline" style="width:300px">
                 {:token()}
                 <input type="text" name="file"  autocomplete="off" placeholder="" readonly class="layui-input file">                     
        </div>
  


        <button type="button" class="layui-btn layui-btn-primary" id="upload-file">上传文件</button>  
        <div class="layui-form-mid layui-word-aux">允许上传的附件类型：{$settings['attachments']['files_ext']?$settings['attachments']['files_ext']:config('app.upload_files.ext')}</div>
        <div class="layui-form-mid layui-word-aux">最大尺寸：{$settings['attachments']['files_size']?format_bytes($settings['attachments']['files_size']):format_bytes(config('app.upload_files.size'))}</div>
        
      </div>
     
      
    </p>
  
   <p style="text-align:center">
   <a href="javascript:;" class="layui-btn layui-btn-normal ship" lay-submit lay-filter="ship" >确认发货</a></p>
     </form>
   {elseif $Request.param.step ==5}
    <!-- 我已发货，等待买家确认 -->
    {if $guaranteeData.file}
    <div style="text-align:center;" class= ><a href="{$guaranteeData.file}" class="layui-icon layui-icon-download-circle" style="font-size:35px;margin:0 auto">源文件下载</a></div>
    {/if}

    <h2 style="text-align:center;padding:40px;">我已经发货，等待买家确认！</h2>

   <p style="text-align:center;margin-bottom:10px;color:red">订单自动确认时间：  <span id="auto_time"></span>
    </p>
    <p style="text-align:center">
    
    {if empty($guaranteeData['rights'])}
    <a href="javascript:;" class="layui-btn layui-btn-primary arbitration"  data-url="{:url('@user/rights/index',['id'=>$Request.param.id,'from'=>$Think.session.uid,'to'=>$guaranteeData.buyer_info.uid])}">申请仲裁</a>
    {else}
      等待仲裁处理！
    {/if}

    </p>

   {elseif $Request.param.step ==6}
      {if $guaranteeData.seller_evaluate > 0 }
        {if $guaranteeData.buyer_evaluate > 0 }
           <h2 style="text-align:center;padding:40px;">双方已评价！</h2>
       {else}
           <h2 style="text-align:center;padding:40px;">我已经评价！</h2>
       {/if} 
     {else}
            <!-- 卖家评价 -->
           <h2 style="text-align:center;padding:40px;">给买家评价！</h2>
           <form class="layui-form" action="">
                  <div class="layui-form-item" >
                    <label class="layui-form-label" style="width:120px">给对方的评价</label>
                    <div class="layui-input-block">
                       <input type="radio" name="seller_evaluate" value="1" title="好评" checked>
                       <input type="radio" name="seller_evaluate" value="2" title="中评" >
                       <input type="radio" name="seller_evaluate" value="3" title="差评" >
                    </div>
                  </div>
                    <div class="layui-form-item layui-form-text">
                      <label class="layui-form-label" style="width:120px">评价内容</label>
                      <div class="layui-input-inline" style="width:420px">
                        <textarea name="seller_evaluate_content" placeholder="请输入评价内容" class="layui-textarea"></textarea>
                      </div>
                    </div>
                      <div class="layui-form-item">
              <label class="layui-form-label" style="width:120px">评价质量</label>
              <div class="layui-input-inline" style="width:620px">
    
                     <div class="layui-form-item">
                      <label class="layui-form-label">付款速度</label>
                       {:choose_stars('seller_pay')}
                    
                    </div>
                       <div class="layui-form-item">
                      <label class="layui-form-label">买家态度</label>
                       {:choose_stars('seller_attitude')}
               
                    </div>
                       <div class="layui-form-item">
                      <label class="layui-form-label">验收及时性</label>
                       {:choose_stars('seller_check')}
          
                    </div>   
              </div>
            </div>
                  <div class="layui-form-item">
                   <label class="layui-form-label" style="width:120px"></label>
                  <div class="layui-input-inline">
                    <button class="layui-btn layui-btn-normal" lay-submit lay-filter="sellerEvaluate">提交</button>
                    
                  </div>
               </div>
            </form>
      {/if}


   {/if}

   {elseif $Request.param.step ==7}  
     <h2 style="text-align:center;padding:40px;">订单已关闭！</h2>
{/if}

</div>

  </div>

</div>

</div>

</div>
</div>


{include file="public/footer"}
<script>
layui.use(['layer','form','layedit','rate','upload'], function(){
  var form = layui.form;
  var layer = layui.layer;
  var layedit = layui.layedit;
  var rate = layui.rate;
  var upload = layui.upload;
  var token = $("input[name='__token__']").val();
   //拖拽上传
  upload.render({
    elem: '#upload-file'
    ,url: '{:url("@user/upload/files")}'
    ,headers: {token:token}
    ,accept:'file'
    ,field:'files[]'
    ,exts:"{$settings['attachments']['files_ext']?str_replace(',','|',$settings['attachments']['files_ext']):str_replace(',','|',config('app.upload_files.ext'))}"
    ,number:1    //允许上传的文件数量
    ,size: "{$settings['attachments']['files_size']?$settings['attachments']['files_size']:config('app.upload_files.size')}"   
    ,auto:true
    ,done: function(res){
      layer.msg(res.msg);
      $(".file").val(res.data);
  
    }
  });


// 卖家发货
form.on('submit(ship)',function(data){
  var url = "{:url('@user/guarantee/updateOrderStatus')}";
    if(url ==''){
      layer.msg('请求的url不存在');
    }
      $.post(url,data.field,function(json){
        if(json.code == '0'){
          qilecms.success(json.msg);
          location.reload();
        }else{
          qilecms.error(json.msg);
        }
      });
});


// 卖家 接受订单
  $(".accept").on("click",function(){
    var url = $(this).attr('data-url');
    $.get(url,function(json){ 
       if(json.code == 0){
          layer.msg(json.msg);
          location.reload();
       }else{
          layer.msg(json.msg);
       }
    });
  });
//取消订单
 $(".refuse").on("click",function(){
     var url = $(this).attr('data-url');
    $.get(url,function(json){
       if(json.code == 0){
          layer.msg(json.msg);
           location.reload();
       }else{
        layer.msg(json.msg);
       }
    });
  });

// 买家付款
  $(".pay").on("click",function(){
    var url = $(this).attr('data-url');
    $.get(url,function(json){ 
       if(json.code == 0){
          qilecms.success(json.msg);
          location.reload();
       }else{
          qilecms.error(json.msg);
       }
    });
  });

// 买家确认

$(".buyerConfirm").on("click",function(){
      $.get("{:url('@user/guarantee/updateOrderStatus',['id'=>$Request.param.id,'status'=>4])}",function(json){
       if(json.code == 0){
           qilecms.success(json.msg); 
           location.reload();
       }else{
           qilecms.error(json.msg);
       }
    });
});


// 买家给卖家评价
  form.on('submit(buyerEvaluate)', function(data){
  var url = "{:url('@user/guarantee/evaluate',['id'=>$Request.param.id])}";
    $.post(url,data.field,function(json){
      if(json.code == '0'){
        qilecms.success(json.msg);
        location.reload();
      }else{
        qilecms.error(json.msg);
      }
    });
    return false;
 });

// 卖家给买家评价
  form.on('submit(sellerEvaluate)', function(data){
  var url = "{:url('@user/guarantee/evaluate',['id'=>$Request.param.id])}";
    $.post(url,data.field,function(json){
      if(json.code == '0'){
        qilecms.success(json.msg);
        location.reload();
      }else{
        qilecms.error(json.msg);
      }
    });
   

    return false;

  });
//仲裁

$(".arbitration").on("click",function(){
var url = $(this).attr('data-url');
  layer.open({
  type: 2,
  title: '申请维权',
  shade: 0.8,
  area: ['600px', '77%'],
  content:url
  }); 

});



});
</script>
    <script>
      layui.use(['util', 'laydate', 'layer'], function(){
        var util = layui.util
        ,laydate = layui.laydate
        ,layer = layui.layer;

        
        //倒计时
        var thisTimer, setCountdown = function(y, M, d, H, m, s){
          var endTime = new Date(y, M-1||0, d||1, H||0, m||0, s||0) //结束日期
          ,serverTime = new Date(); //假设为当前服务器时间，这里采用的是本地时间，实际使用一般是取服务端的
          clearTimeout(thisTimer);
          util.countdown(endTime, serverTime, function(date, serverTime, timer){
            var str = date[0] + '天' + date[1] + '时' +  date[2] + '分' + date[3] + '秒';
            lay('#auto_time').html(str);
            thisTimer = timer;
          });
        };
        var  year = "{$guaranteeData.auto_confirm_time|date='Y'}";
        var  month = "{$guaranteeData.auto_confirm_time|date='m'}";
        var  day= "{$guaranteeData.auto_confirm_time|date='d'}";
        
        var  H= "{$guaranteeData.auto_confirm_time|date='H'}";
        var  i= "{$guaranteeData.auto_confirm_time|date='i'}";
        var  s= "{$guaranteeData.auto_confirm_time|date='s'}";
        setCountdown(year,month,day,H,i,s);

      });
      </script>
</body>
</html>